//根据 指定id 获取 树形节点
export function getTreeNodeById (data, id) {
    for (let i = 0; i < data.length; i++) {
        let item = data[i]
        if (item.hasOwnProperty("id")){
            if (item.id === id) {
                return item;	// 返回结果
            } else {
                if (item.children && item.children.length > 0) {
                    let res = getTreeNodeById(item.children, id);
                    if (res){
                        return res
                    }
                }
            }
        }else {
            break;
        }
    }
}

//根据 指定追溯节点ID 获取 直系祖先节点ID数组
export function getAllParentId(nodeArr, retrospectNodeId) {
    const searchedArr = []
    const fn = (nodeArr, retrospectNodeId) => {
        const pNode = getTreeNodeById(nodeArr,retrospectNodeId)
        if (pNode) {
            searchedArr.push(pNode.id)
            fn(nodeArr, pNode.pId)
        }
    }
    fn(nodeArr, retrospectNodeId)
    return searchedArr.reverse()
}
